In this lab, we need to implement a simple Unix style shell program. The file we only need to modify is tsh.c in handout package.
We should implement those functions:
eval parse and execute the instruction that user has inputted.
builtin_cmd check if the command inputted is a inner build command. Such as quitfgbg
do_bgfg It define the behaviors how to execute back ground and front ground command.
waitfg wait until the front ground program done.
sigchld_handler process SIGCHLD signal, when son process stopped or terminated.
sigint_handler process SIGINT signal, interrupt from keyboard ctrl-c.
sigstp_handler process SIGTSTP signal, interrupt from keyboard ctrl-z.
You can use make test(n) to test your shell program on n-th test set. For example, if you have implemented all functions this lab required. You can use make test15 to test your tsh.
Methods
1. eval
Just borrowed the code from csapp 🙂.
A quick review of signal process function. If you want to use those functions, you need include signal.h first.
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) Use how to tell function, which way we want to change the blocked signal set. If how = SIG_BLOCK, blocked = blocked | set if how = SIG_UNBLOCK, blocked = blocked & ~set if how = SETMASK, block = set if oldset is not empty, the previous blocked status will be stored in oldset, for recovery purpose.
int sigemptyset(sigset_t *set) Init set to 0.
int sigfillset(sigset_t *set) Get current signals.
int sigaddset(sigset_t *set, int signum) Add signum to signal set.
int sigdelset(sigset_t *set, int signum) Delete signum from signal set.
int sigismember(const sigset_t *set, int signum) If signum in signal set, return 1 else return 0.